import { Connector } from "cax-connector";
import { devtool } from "cax-base";
import {
  API_EVENT,
  CurveMeshOptions,
  IReq,
  IRes,
  SurfaceMeshOptions,
} from "../interface";
import { v4 as uuidv4 } from "uuid";

export function mesh_detach(
  this: Connector,
  EntityIds: Array<number>,
  PartId: number
): Promise<string> {
  if (this.client == null) return Promise.reject("socket未初始化");
  const req: IReq = {
    Topic: "api",
    Type: API_EVENT.MESH_DETACH,
    Params: {
      EntityIds,
      PartId,
    },
    Req: 1,
    Res: 0,
    Tag: uuidv4(),
  };
  this.client.emit("api", req);
  return new Promise((resolve, reject) => {
    this.client?.once(req.Tag, (ev: IRes) => {
      devtool.success("mesh_detach", ev);
      if (ev.Status === 0) {
        resolve(ev.Result);
      } else {
        reject(ev.Errmsg);
      }
    });
  });
}
